package com.zb.model.common;

import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@NoArgsConstructor
public class Result<T> implements Serializable {

    private Integer code;// 返回码
    private String message;//返回信息
    private Object data;// 返回数据

    public Result(Integer code,String message) {
        this.code = code;
        this.message = message;
    }
    public Result(Integer code,String message,T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static Result SUCCESS(){
        Result result =  new Result(200, "操作成功");
        return result;
    }

    public static <T> Result<T> SUCCESS(T data){
        Result<T> result =  new Result(200, "操作成功");
        result.setData(data);
        return result;
    }

    public static <T> Result<T> SUCCESS(String msg){
        return new Result(200, msg);
    }

    public static Result ERROR(){
        return new Result(201,"操作失败");
    }

    public static Result FAIL(){
        return new Result(202, "服务器内部错误");
    }
}
